#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
void main()
{
    // pid_t pid_me,pid_p,pid_g;
    // pid_me=getpid();
    // pid_p=getppid();
    // pid_g=__getpgid(pid_me);
    // printf("%d %d %d\n",pid_me,pid_p,pid_g);
    pid_t child_pid;
    child_pid =vfork();
    if(child_pid<0)
    {
        printf("create exe fail\n");
        
    }
    if(child_pid==0)
    {
        for(int i=0;i<3;i++)
        {
            printf("this is a child process\n");
            //printf("%d %d %d\n",getpid(),getppid,__getpgid(getpid()));
        }
        exit(2);
    }
    else
    {
        int status=0;
        printf("this is a parent process\n");
        //printf("%d %d %d %d\n",child_pid,getpid(),getppid,__getpgid(getpid()));
        //wait(&status);
        waitpid(child_pid,&status,0);
        if(WIFEXITED(status)!=0)
        {
            printf("child die! the status of child exit is %d\n",WEXITSTATUS(status));
        }
    }
}